<template>
  <div class="manage_page">
    <head-top></head-top>
    <div class="manage_list">
      <div class="create">
        <el-menu
          default-active="1"
          background-color="#7878D1"
          text-color="#fff"
          active-text-color="black"
        >
          <el-submenu index="1">
            <template slot="title">
              <i
                class="el-icon-circle-plus-outline"
                style="padding-right: 8px; font-size: 20px; color: whitesmoke"
              ></i>
              <span style="font-size: 16px; color: whitesmoke">新建问卷</span>
            </template>
            <el-menu-item index="1-1" @click="ShowTileCreate">
                <i
                class="iconfont myicon-tiaochawenjuan"
                style="color: white"></i>
              普 通 问 卷</el-menu-item>

            <el-menu-item index="1-2"  @click="ShowTileCreate1"
              ><i class="iconfont myicon-menu_zxtp" style="color: white"></i> 投
              票 问 卷</el-menu-item
            >
            <el-menu-item index="1-3" @click="ShowTileCreate2"
              ><i
                class="iconfont myicon-kaoshitianchong"
                style="color: white"
              ></i>
              考 试 问 卷</el-menu-item
            >
            <el-menu-item index="1-4" @click="ShowTileCreate3"
              ><i
                class="iconfont myicon-xinxueyuanbaoming"
                style="color: white"
              ></i>
              报 名 问 卷</el-menu-item
            >
            <el-menu-item index="1-5" @click="CreateSpecial('Y')"
              ><i
                class="iconfont myicon-daqia"
                style="color: white"
              ></i>
              疫 情 打 卡</el-menu-item
            >
          </el-submenu>
        </el-menu>
      </div>
      <div style="width: 70%; margin-top: 10px">
        <el-menu default-active="manage" active-text-color="#5757a8" router>
          <el-menu-item index="manage">
            <i
              class="iconfont myicon-wenjuanguanli"
              style="font-size: 18px; padding-right: 10px"
            ></i
            >全部问卷
          </el-menu-item>
          <el-menu-item index="recyclebin">
            <i
              class="iconfont myicon-huishouzhan"
              style="font-size: 18px; padding-right: 10px"
            ></i
            >回收站
          </el-menu-item>
        </el-menu>
      </div>
    </div>
    <div style="padding-top: 40px">
      <router-view></router-view>
    </div>

    <el-dialog title="" id="dialog" :visible.sync="dialogFormVisible">
      <div class="inner" style="">
        <span>创建调查问卷</span>
          <br><br><br>
          <el-input v-model="input" placeholder="请输入标题" style="width:70%;"></el-input>
          <br><br><br><br><br>
          <el-button type="primary" @click="Create">创建问卷</el-button>
      </div>
    </el-dialog>

    <el-dialog title="" id="dialog" :visible.sync="dialogFormVisible1">
      <div class="inner" style="">
        <span>创建投票问卷</span>
          <br><br><br>
          <el-input v-model="input" placeholder="请输入标题" style="width:70%;"></el-input>
          <br><br><br><br><br>
          <el-button type="primary" @click="CreateSpecial('V')">创建问卷</el-button>
      </div>
    </el-dialog>

    <el-dialog title="" id="dialog" :visible.sync="dialogFormVisible2">
      <div class="inner" style="">
        <span>创建考试问卷</span>
          <br><br><br>
          <el-input v-model="input" placeholder="请输入标题" style="width:70%;"></el-input>
          <br><br><br><br><br>
          <el-button type="primary" @click="CreateSpecial('E')">创建问卷</el-button>
      </div>
    </el-dialog>

    <el-dialog title="" id="dialog" :visible.sync="dialogFormVisible3">
      <div class="inner" style="">
        <span>创建报名问卷</span>
          <br><br><br>
          <el-input v-model="input" placeholder="请输入标题" style="width:70%;"></el-input>
          <br><br><br><br><br>
          <el-button type="primary" @click="CreateSpecial('A')">创建问卷</el-button>
      </div>
    </el-dialog>
  <!--  
    <el-dialog title="" id="dialog" :visible.sync="dialogFormVisible4">
      <div class="inner" style="">
        <span>创建疫情打卡问卷</span>
          <br><br><br>
          <el-input v-model="input" placeholder="请输入标题" style="width:70%;"></el-input>
          <br><br><br><br><br>
          <el-button type="primary" @click="CreateSpecial('Y')">创建问卷</el-button>
      </div>
    </el-dialog>
  -->
    
  </div>
</template>

<script>
import headTop from "../../components/headTop.vue";
import {creQuestionnaire,createSpecialQuestionNare,createYiQingQuestionNare} from '../../api'
export default {
  data() {
    return {
      uid: '',
      dialogFormVisible: false,
      dialogFormVisible1:false,
      dialogFormVisible2:false,
      dialogFormVisible3:false,
      dialogFormVisible4:false,
      input: '',

    };
  },
  components: {
    headTop,
  },
  computed: {

  },
  mounted() {
    this.uid = this.$store.state.uid;
  },
  methods: {
    ShowTileCreate() {
      this.dialogFormVisible=true;
    },
    ShowTileCreate1() {
      this.dialogFormVisible1=true;
    },
    ShowTileCreate2() {
      this.dialogFormVisible2=true;
    },
    ShowTileCreate3() {
      this.dialogFormVisible3=true;
    },
    ShowTileCreate4() {
      this.dialogFormVisible4=true;
    },
    /*
    CreateNormalQN(){
      this.$router.push('/normalquestionnare')
    },
    */
    Create() {
			creQuestionnaire(this.uid, this.input).then(res => {
				console.log(res);
				const x=res.error_code;
        switch (x){
					case -1:alert("未知错误");break;
          case 0:
            this.$router.push({name: 'normalquestionnare', query: {questionnaireId: this.$UrlEncode.encode(JSON.stringify(res.questionnaire_id*1234))}});
            break;
          case 1:alert("请求参数错误");break;
          case 2:alert("用户不存在");break;
          case 3:alert("标题不合法");break;
        }
			})
    },
    CreateSpecial(type){
      if(type=='E'){
        createSpecialQuestionNare(this.uid, this.input,type).then(res => {
        console.log(type)
        
				console.log(res);
				const x=res.error_code;
        switch (x){
					case -1:alert("未知错误");break;
          case 0:this.$router.push({name: 'examquestionnare', query: {questionnaireId: this.$UrlEncode.encode(JSON.stringify(res.questionnaire_id*1234)), index: this.$UrlEncode.encode(JSON.stringify(qid))}});break;
          case 1:alert("请求参数错误");break;
          case 2:alert("用户不存在");break;
          case 3:alert("标题不合法");break;
        }
			})
      }
      else if(type=='V'){
        createSpecialQuestionNare(this.uid, this.input,type).then(res => {
        console.log(type)
        
				console.log(res);
				const x=res.error_code;
        switch (x){
					case -1:alert("未知错误");break;
          case 0:this.$router.push({name: 'votequestionnare', query: {questionnaireId: this.$UrlEncode.encode(JSON.stringify(res.questionnaire_id*1234))}});break;

          case 1:alert("请求参数错误");break;
          case 2:alert("用户不存在");break;
          case 3:alert("标题不合法");break;
        }
			})
      }
      else if(type=='Y'){
        createYiQingQuestionNare(this.uid).then(res => {
        console.log(type)
        
				console.log(res);
				const x=res.error_code;
        switch (x){
					case -1:alert("未知错误");break;
          case 0:this.$router.push({name: 'yiqingquestionnare', query: {questionnaireId: this.$UrlEncode.encode(JSON.stringify(res.new_questionnaire_id*1234))}});break;
          case 1:alert("请求参数错误");break;
          case 2:alert("用户不存在");break;
          case 3:alert("标题不合法");break;
        }
			})
      }
      else if(type=='A'){
        createSpecialQuestionNare(this.uid, this.input,type).then(res => {
        console.log(type)
        
				console.log(res);
				const x=res.error_code;
        switch (x){
					case -1:alert("未知错误");break;
          case 0:this.$router.push({name: 'applyquestionnare', query: {questionnaireId: this.$UrlEncode.encode(JSON.stringify(res.questionnaire_id*1234))}});break;
          case 1:alert("请求参数错误");break;
          case 2:alert("用户不存在");break;
          case 3:alert("标题不合法");break;
        }
			})
      }
      else if(type=='Y'){
        createYiQingQuestionNare(this.uid).then(res => {
        console.log(type)
        
				console.log(res);
				const x=res.error_code;
        switch (x){
					case -1:alert("未知错误");break;
          case 0:this.$router.push({name: 'yiqingquestionnare', query: {questionnaireId:this.$UrlEncode.encode(JSON.stringify(res.new_questionnaire_id*1234))}});break;
          case 1:alert("请求参数错误");break;
          case 2:alert("用户不存在");break;
          case 3:alert("标题不合法");break;
        }
			})
      }
      }
      
  },
};
</script>

<style>
.manage_page {
  height: 100%;
  background-color: rgb(244, 240, 248);
  text-align: left;
  background-size: cover;
	overflow: auto;
}
.manage_list {
  margin-left: 70px;
  height: 80%;
  width: 350px;
  float: left;
}
.create {
  width: 70%;
  margin-top: 30px;
}
.inner{
  height: 350px;
  width: 100%;
  text-align: center;
	font-size: 25px;
}

</style>